package landian.com.module_base;

import java.lang.ref.WeakReference;

import landian.com.module_base.mvp.IPresenter;
import landian.com.module_base.mvp.IView;

/**
 * Created by Administrator on 2019-03-04.
 */

public class BasePresenter<V extends IView> implements IPresenter<V> {

    private WeakReference<V> mWeakReference;

    @Override
    public V getView() {
        if (mWeakReference != null)
            return mWeakReference.get();
        throw new NullPointerException("the view has been detached from the activity");
    }

    @Override
    public void attachView(V view) {
        mWeakReference = new WeakReference<>(view);
    }

    @Override
    public void detachView() {
        if (mWeakReference != null)
            mWeakReference = null;
    }
}
